package com.dagger.common;

import java.io.Serializable;

import lombok.Data;

/**
 * rest接口返回对象
 * 
 * @author dagger
 *
 * @param <T>
 */
@Data
public class RestResult<T> implements Serializable {
	public static String MSG_QUERY_SUCCESS = "查询成功";
	public static String MSG_ADD_SUCCESS = "新增成功";
	public static String MSG_UPDATE_SUCCESS = "修改成功";
	public static String MSG_DELETE_SUCCESS = "删除成功";
	public static String AUDIT_DELETE_SUCCESS = "审核成功";
	public static String MSG_UPLOAD_SUCCESS = "上传成功";
	public static String MSG_EXPORT_SUCCESS = "导出成功";
	public static String MSG_IMPORT_SUCCESS = "导入成功";
	public static String MSG_LOGOUT_SUCCESS = "登出成功";
	public static String MSG_OPERATE_SUCCESS = "操作成功";
	public static String MSG_OPERATE_ERROR = "操作失败";

	private static final long serialVersionUID = -3658656979748841873L;

	private String msg;

	private int code = 200;

	private T data;

	public RestResult(int code, String msg) {
		this();
		setCode(code);
		setMsg(msg);
	}

	public RestResult() {
	}

	public RestResult(int code, String msg, T data) {
		this();
		setCode(code);
		setMsg(msg);
		setData(data);
	}

	public static RestResult<String> MsgResult(String msg) {
		return new RestResult<String>(200, msg);
	}

	public static <T> RestResult<T> searchSuccess(T data) {
		return new RestResult<>(200, MSG_QUERY_SUCCESS, data);
	}

	public static <T> RestResult<T> importSuccess(T data) {
		return new RestResult<>(200, MSG_IMPORT_SUCCESS, data);
	}

	public static <T> RestResult<T> saveSuccess(T data) {
		return new RestResult<>(200, MSG_ADD_SUCCESS, data);
	}
}
